package cn.zw.test;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

 /**
  *    
  *     一个线程中可以共享  一个数据
  *     
  *     
  *     静态方法中，想要访问内部类，需要把类静态化。
  *     
  *     
  *     
  * 	
  *
  */
public class Tes {
	
	public  static  Map<Thread, Integer> threadData = new HashMap<Thread, Integer>();
	
	public  void  testStaticClass(){
		
		new C();
		
		
	}
	
	
	public static void main(String[] args) {
		
		for (int i = 0; i < 2; i++) {
			
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					int  data =  new Random().nextInt();
					threadData.put(Thread.currentThread(), data);
					new A().get();
					new B().get2();
				}
			}).start();
			
		}
		
		
	}
	
	
	
	
  static  class A{
	
	  public  void  get(){
		  
		Integer data =   threadData.get(Thread.currentThread());
		  System.out.println("当前类A："+"当前线程:"+Thread.currentThread()+"\t"+data);
		  
	  
	}
  }
	  
  static class B{
	  
	  public  void get2(){
			Integer data =   threadData.get(Thread.currentThread());
			  System.out.println("当前类B："+"当前线程:"+Thread.currentThread()+"\t"+data);
			  
	  }
	  
  }
	
  
  class  C{
	 
	 
 }
	
	
	
	
}

	
